package com.ranjiaqi.thread08;

/**
 * @ClassName DeadLockTest
 * @Description TODO
 * @Author hp
 * @Date 2021/6/28 20:12
 * @Version 1.0
 **/
public class DeadLockTest implements Runnable {
    private boolean flag;

    public DeadLockTest(boolean flag) {
        this.flag = flag;
    }

    @Override
    public void run() {
        while (true){
            if (flag){
                synchronized (LocakA.lockA){
                    System.out.println("if.....A");
                    synchronized (LocakB.lockB){
                        System.out.println("if....B");
                    }
                }
            }else {
                synchronized (LocakB.lockB){
                    System.out.println("else....B");
                    synchronized (LocakA.lockA){
                        System.out.println("else....A");
                    }
                }
            }
        }
    }
}
